package com.xxrl.shop.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @author mis
 */
@ApiModel(description = "Merchant information")
@Data
@NoArgsConstructor
@Entity
@Table(name = "sp_merchant")
@EntityListeners(AuditingEntityListener.class)
public class Merchant implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(notes = "Unique identifier of the Merchant.", example = "1",
            required = true)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @OneToOne
    @JoinColumn(name = "user_id", unique = true)
    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @JsonIgnore
    @JSONField(serialize = false)
    private User user;

    @ApiModelProperty(hidden = true)
    @OneToMany(mappedBy = "merchant")
    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @JsonIgnore
    @JSONField(serialize = false)
    private Set<Product> products = new HashSet<>();

    /**
     * 商家的信息
     */
    @ApiModelProperty(notes = "Description of merchant, decoded html data.",
            example = "This is my little shop :).")
    private String content;

    @CreatedDate
    private Long createTime;

    @LastModifiedDate
    private Long lastModifiedTime;
    
    public Merchant(Long id) {
        this.id = id;
    }
}
